import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;

public class TestDraw_new {
	public static void main(String[] args) {
		DrawPanel_new drawPanelNew=new DrawPanel_new(generateShapes());
		JFrame application = new JFrame();
		application.setTitle("第一题");
		application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		application.add(drawPanelNew);
		application.setSize(400, 300);
		application.setVisible(true);
	}
	public static Shapes[] generateShapes() {
		Scanner in=new Scanner(System.in);
		int currentShapes=3;
		ArrayList<Integer> shapes=new ArrayList<>();
		for(int i=1;i<=currentShapes;i++){
			shapes.add(i);
		}
		System.out.println("请输入你想生成的图形。1-线 2-圆 3-矩形");
		int ans;
		while (true){
			try {
				ans= in.nextInt();
				if(!shapes.contains(ans)){
					System.out.println("目前没有第"+ans+"个图形");
					continue;
				}
				break;
			} catch (InputMismatchException e) {
				System.out.println("请在给定的范围输入数字");
				continue;
			}
		}
		Shapes[] result=new Shapes[15];
		for (int i = 0; i < 15; i++) {
			result[i]=generate(ans);
		}
		return result;
    }//配合新的DrawPanel_new可以定制输出内容（只有圆、只有线、只有矩形。）
	public static Shapes generate(int type){
		switch (type){
			case 1:{
				MyLine myLine=new MyLine();
				myLine= (MyLine) myLine.random();
				return myLine;
			}
			case 2:{
				MyCircle myCircle=new MyCircle();
				myCircle=(MyCircle) myCircle.random();
				return myCircle;
			}
			case 3:{
				MyRectangle myRectangle=new MyRectangle();
				myRectangle=(MyRectangle) myRectangle.random();
				return myRectangle;
			}
			default:{
				return null;
			}
		}
	}

}
